package yunjiao.javatutorials.designpatterns.interpreter;

import lombok.Getter;

import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;

/**
 * 经理
 *
 * @author yangyunjiao
 */
@Getter
public class Manager extends Employee {
    List<Employee> managingEmployees = new ArrayList<Employee>();

    public Manager(long employeeId, String employeeName, String designation, Department department, int salary) {
        super(employeeId, employeeName, designation, department, salary);
    }


    public boolean manages(Employee employee) {
        return managingEmployees.add(employee);
    }

    public boolean stopManaging(Employee employee) {
        return managingEmployees.remove(employee);
    }


    @Override
    public int teamSize() {
        return managingEmployees.stream().mapToInt(Employee::teamSize).sum();
    }

    @Override
    public boolean isManager() {
        return true;
    }

    @Override

    public String teamNames() {
        return "{" + managingEmployees.stream().map(employee -> {
            if (employee.isManager()) {
                return employee.getEmployeeName() + " " + employee.teamNames();
            } else {
                return employee.getEmployeeName();
            }
        }).collect(Collectors.joining(", ")) +
                "}";

    }
}
